package cc.mrbird.febs.log.dao;

import cc.mrbird.febs.log.domain.LogBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface LogMapper {
    @Select("SELECT * FROM febs_spark_log_pv.t_log_uv where time like concat(concat('%', #{time}), '%')")
    List<LogBean> listUv(@Param("time") String time);

    @Select("SELECT time, sum(pv) pv FROM febs_spark_log_pv.t_log_pv \n" +
            "where time like concat(concat('%', #{time}), '%') group by time")
    List<LogBean> listPv(@Param("time") String time);

    @Select("SELECT time, count(distinct ip) ip FROM febs_spark_log_pv.t_log_pv \n" +
            "where time like concat(concat('%', #{time}), '%') group by time")
    List<LogBean> listIp(@Param("time") String time);

    @Select("select pv, uv, cnt/ip pu, cnt/uv pp  from (\n" +
            "SELECT sum(uv) uv FROM febs_spark_log_pv.t_log_uv where time like concat(concat('%', #{time}), '%')\n" +
            ") a left join (\n" +
            "SELECT sum(pv) pv, sum(cnt) cnt FROM febs_spark_log_pv.t_log_pv where time like concat(concat('%', #{time}), '%')\n" +
            ") b on 1=1 left join (\n" +
            "SELECT count(distinct ip) ip FROM febs_spark_log_pv.t_log_pv where time like concat(concat('%', #{time}), '%')\n" +
            ") c on 1=1\n")
    Map<String, Object> countLog(@Param("time") String time);
}
